package com.xcity.game.vip;

import java.util.ArrayList;
import java.util.List;

import naga.x.App;
import naga.x.util.StringUtils;

public class VipUtils {

	public static VipTemplate getTemplate(int level) {
		return App.getApp().getServiceManager().get(VipService.class).get(level);
	}
	
	public static String getBestMatchHeadIcon(int level) {
		VipService service = App.getApp().getServiceManager().get(VipService.class);
		VipTemplate vt = service.get(level);
		while (vt != null && StringUtils.isEmpty(vt.getHeadIcon())) {
			vt = service.get(--level);
		}
		return vt != null ? vt.getHeadIcon() : null;
	}
	
	public static int getMaxLevel() {
		return VipService.VIP_MAX_LEVEL;
	}
	
	public static List<Integer> getSweepCountList(int level, int leftCount){
		List<Integer> list = App.getApp().getServiceManager().get(VipService.class).getSweepCountList(level);
		List<Integer> retList = new ArrayList<Integer>();
		retList.addAll(list);
		for(int i = retList.size() - 1; i > -1; i--){
			if(retList.get(i) > leftCount){
				retList.remove(i);
			}
		}
		return list;
	}
	
	public static int getNextVipLevel(int currentLevel, int requestSweepCount){
		VipService vs = App.getApp().getServiceManager().get(VipService.class);
		int ret = -1;
		int currentCount = vs.get(currentLevel).getSweepCount();
		for(int i = currentCount + 1; i <= VipService.VIP_MAX_LEVEL; i++){
			if(vs.get(i).getSweepCount() == requestSweepCount){
				ret = i;
				break;
			}
		}
		return ret;
	}
}
